package com.ocom.payconfig.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ocom.common.entity.card.EntityXfSubAccountList;
import com.ocom.common.request.callpackage.QuerySubAccountResponse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface IDaoXfSubAccountList extends BaseMapper<EntityXfSubAccountList> {

    @Select({"<script>",
            "SELECT\n" +
                    " wi.sub_account as subAccount,\n" +
                    " wt.sub_account_name as subAccountName,\n" +
                    " wi.account_recharge_money as rechargeBalance,\n" +
                    " wi.account_subsidy_money as subsidyBalance\n" +
                    " FROM\n" +
                    " xf_sub_account_list wi\n" +
                    " LEFT JOIN xf_sub_account wt ON wi.com_id = wt.com_id\n" +
                    " AND wi.sub_account = wt.sub_account\n" +
                    " WHERE\n" +
                    " wi.com_id = #{comId}\n" +
                    " AND wi.p_id = #{pId}\n" +
                    " <when test=\"subAccount != null\" > " +
                    "   AND wi.sub_account = #{subAccount}" +
                    " </when>" +
                    " limit 1 " +
                    "</script>"})
    QuerySubAccountResponse querySubAccount(@Param("comId") Long comId, @Param("pId")Long pId, @Param("subAccount")Integer subAccount);

}
